package view.dialog;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.UIManager;
import javax.swing.WindowConstants;

import lib.MyUtils;
import view.Home;
import view.employee.EmployeeMainPanel;
import controller.employee.ChangePasswordController;

public class EmployeeChangePasswordDialog extends JDialog {

	private EmployeeMainPanel emp;
	
	private static final long serialVersionUID = 1L;
	private JButton btn_emdlg_cancel;
	private JButton btn_emdlg_savechange;
	private JComboBox<String> cbb_emdlg_sex;
	private com.toedter.calendar.JDateChooser dc_emdlg_birthday;
	private JScrollPane jScrollPane1;
	private JLabel lbl_emdlg_address;
	private JLabel lbl_emdlg_birthday;
	private JLabel lbl_emdlg_email;
	private JLabel lbl_emdlg_name;
	private JLabel lbl_emdlg_newpassword;
	private JLabel lbl_emdlg_personalID;
	private JLabel lbl_emdlg_phone;
	private JLabel lbl_emdlg_sex;
	private JPanel pn_emdlg_changeinfor;
	private JTextField txt_emdlg_email;
	private JTextField txt_emdlg_name;
	private JPasswordField txt_emdlg_newpassword;
	private JTextField txt_emdlg_personalID;
	private JTextField txt_emdlg_phone;
	private JTextArea txta_emdlg_address;
	
	public static ChangePasswordController controller;
	

	private static EmployeeChangePasswordDialog instance;

	public static EmployeeChangePasswordDialog getInstance() {
		if (instance == null) {
			return instance = new EmployeeChangePasswordDialog(Home.getInstance(),
					true);
		}
		return instance;
	}

	private EmployeeChangePasswordDialog(JFrame parent, boolean modal) {
		super(parent, modal);
		initComponents();
		btn_emdlg_cancel.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				MyUtils.doDispose(getInstance());
			}
		});
	}


	public EmployeeChangePasswordDialog(
			EmployeeChangePasswordDialog employeeChangePasswordDialog) {
		// TODO Auto-generated constructor stub
	}

	private void initComponents() {
		
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		pn_emdlg_changeinfor = new JPanel();
		lbl_emdlg_name = new JLabel();
		lbl_emdlg_personalID = new JLabel();
		lbl_emdlg_address = new JLabel();
		lbl_emdlg_phone = new JLabel();
		lbl_emdlg_email = new JLabel();
		lbl_emdlg_birthday = new JLabel();
		lbl_emdlg_sex = new JLabel();
		txt_emdlg_name = new JTextField();
		jScrollPane1 = new JScrollPane();
		txta_emdlg_address = new JTextArea();
		txt_emdlg_personalID = new JTextField();
		txt_emdlg_phone = new JTextField();
		txt_emdlg_email = new JTextField();
		cbb_emdlg_sex = new JComboBox<String>();
		dc_emdlg_birthday = new com.toedter.calendar.JDateChooser();
		lbl_emdlg_newpassword = new JLabel();
		txt_emdlg_newpassword = new JPasswordField();
		btn_emdlg_savechange = new JButton();
		btn_emdlg_cancel = new JButton();
		
		controller = new ChangePasswordController(this);
//		empChange = new EmployeeChangePasswordDialog(this);
		
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		setTitle("Personal Detail");
		setResizable(false);

		lbl_emdlg_name.setFont(new java.awt.Font("Calibri", 0, 12));
		lbl_emdlg_name.setText("Name:");

		lbl_emdlg_personalID.setFont(new java.awt.Font("Calibri", 0, 12));
		lbl_emdlg_personalID.setText("Personal ID:");

		lbl_emdlg_address.setFont(new java.awt.Font("Calibri", 0, 12));
		lbl_emdlg_address.setText("Address:");

		lbl_emdlg_phone.setFont(new java.awt.Font("Calibri", 0, 12));
		lbl_emdlg_phone.setText("Phone:");

		lbl_emdlg_email.setFont(new java.awt.Font("Calibri", 0, 12));
		lbl_emdlg_email.setText("Email:");

		lbl_emdlg_birthday.setFont(new java.awt.Font("Calibri", 0, 12));
		lbl_emdlg_birthday.setText("Birthday:");

		lbl_emdlg_sex.setFont(new java.awt.Font("Calibri", 0, 12));
		lbl_emdlg_sex.setText("Sex:");

		txta_emdlg_address.setColumns(20);
		txta_emdlg_address.setRows(5);
		jScrollPane1.setViewportView(txta_emdlg_address);

		cbb_emdlg_sex.setModel(new DefaultComboBoxModel<String>(new String[] {
				"Female", "Male", "Other"}));

		lbl_emdlg_newpassword.setText("New Password:");

		btn_emdlg_savechange.setIcon(new ImageIcon("icon/save.png"));
		btn_emdlg_savechange.setText("Save change");

		btn_emdlg_cancel.setIcon(new ImageIcon("icon/cancle.png"));
		btn_emdlg_cancel.setText("Cancel");

		GroupLayout pn_emdlg_changeinforLayout = new GroupLayout(
				pn_emdlg_changeinfor);
		pn_emdlg_changeinfor.setLayout(pn_emdlg_changeinforLayout);
		pn_emdlg_changeinforLayout
				.setHorizontalGroup(pn_emdlg_changeinforLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addGroup(
								pn_emdlg_changeinforLayout
										.createSequentialGroup()
										.addGroup(
												pn_emdlg_changeinforLayout
														.createParallelGroup(
																GroupLayout.Alignment.LEADING)
														.addGroup(
																pn_emdlg_changeinforLayout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addGroup(
																				pn_emdlg_changeinforLayout
																						.createParallelGroup(
																								GroupLayout.Alignment.LEADING)
																						.addComponent(
																								lbl_emdlg_name)
																						.addComponent(
																								lbl_emdlg_personalID)
																						.addComponent(
																								lbl_emdlg_address)
																						.addComponent(
																								lbl_emdlg_phone)
																						.addComponent(
																								lbl_emdlg_email)
																						.addComponent(
																								lbl_emdlg_sex)
																						.addComponent(
																								lbl_emdlg_birthday)
																						.addComponent(
																								lbl_emdlg_newpassword))
																		.addGap(31,
																				31,
																				31)
																		.addGroup(
																				pn_emdlg_changeinforLayout
																						.createParallelGroup(
																								GroupLayout.Alignment.LEADING)
																						.addComponent(
																								txt_emdlg_phone,
																								GroupLayout.DEFAULT_SIZE,
																								199,
																								Short.MAX_VALUE)
																						.addComponent(
																								txt_emdlg_email,
																								GroupLayout.DEFAULT_SIZE,
																								199,
																								Short.MAX_VALUE)
																						.addComponent(
																								txt_emdlg_personalID)
																						.addComponent(
																								txt_emdlg_name)
																						.addComponent(
																								jScrollPane1)
																						.addComponent(
																								txt_emdlg_newpassword)
																						.addGroup(
																								pn_emdlg_changeinforLayout
																										.createSequentialGroup()
																										.addGroup(
																												pn_emdlg_changeinforLayout
																														.createParallelGroup(
																																GroupLayout.Alignment.LEADING)
																														.addComponent(
																																cbb_emdlg_sex,
																																GroupLayout.PREFERRED_SIZE,
																																GroupLayout.DEFAULT_SIZE,
																																GroupLayout.PREFERRED_SIZE)
																														.addComponent(
																																dc_emdlg_birthday,
																																GroupLayout.PREFERRED_SIZE,
																																121,
																																GroupLayout.PREFERRED_SIZE))
																										.addGap(0,
																												0,
																												Short.MAX_VALUE))))
														.addGroup(
																pn_emdlg_changeinforLayout
																		.createSequentialGroup()
																		.addGap(33,
																				33,
																				33)
																		.addComponent(
																				btn_emdlg_savechange,
																				GroupLayout.PREFERRED_SIZE,
																				120,
																				GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				btn_emdlg_cancel,
																				GroupLayout.PREFERRED_SIZE,
																				120,
																				GroupLayout.PREFERRED_SIZE)))
										.addContainerGap(
												GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));
		pn_emdlg_changeinforLayout
				.setVerticalGroup(pn_emdlg_changeinforLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addGroup(
								pn_emdlg_changeinforLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												pn_emdlg_changeinforLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																lbl_emdlg_name)
														.addComponent(
																txt_emdlg_name,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pn_emdlg_changeinforLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																lbl_emdlg_personalID)
														.addComponent(
																txt_emdlg_personalID,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pn_emdlg_changeinforLayout
														.createParallelGroup(
																GroupLayout.Alignment.LEADING)
														.addComponent(
																lbl_emdlg_address)
														.addComponent(
																jScrollPane1,
																GroupLayout.PREFERRED_SIZE,
																54,
																GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pn_emdlg_changeinforLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																txt_emdlg_phone,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																lbl_emdlg_phone))
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pn_emdlg_changeinforLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																txt_emdlg_email,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																lbl_emdlg_email))
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pn_emdlg_changeinforLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																cbb_emdlg_sex,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																lbl_emdlg_sex))
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pn_emdlg_changeinforLayout
														.createParallelGroup(
																GroupLayout.Alignment.TRAILING)
														.addComponent(
																dc_emdlg_birthday,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																lbl_emdlg_birthday))
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pn_emdlg_changeinforLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																lbl_emdlg_newpassword)
														.addComponent(
																txt_emdlg_newpassword,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE))
										.addGap(18, 18, 18)
										.addGroup(
												pn_emdlg_changeinforLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																btn_emdlg_savechange,
																GroupLayout.PREFERRED_SIZE,
																30,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btn_emdlg_cancel,
																GroupLayout.PREFERRED_SIZE,
																30,
																GroupLayout.PREFERRED_SIZE))
										.addContainerGap(
												GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));

		btn_emdlg_savechange.getAccessibleContext().setAccessibleName("");
		btn_emdlg_savechange.getAccessibleContext()
				.setAccessibleDescription("");
		
		btn_emdlg_savechange.addActionListener(controller);
			
		
		btn_emdlg_cancel.getAccessibleContext().setAccessibleName("90");
		btn_emdlg_cancel.getAccessibleContext().setAccessibleDescription("30");

		GroupLayout layout = new GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(pn_emdlg_changeinfor,
								GroupLayout.DEFAULT_SIZE,
								GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addContainerGap()));
		layout.setVerticalGroup(layout.createParallelGroup(
				GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(pn_emdlg_changeinfor,
								GroupLayout.DEFAULT_SIZE,
								GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addContainerGap()));

		pack();
	}
	
	public static void main(String args[]) {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, e);
		}
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				EmployeeChangePasswordDialog dialog = new EmployeeChangePasswordDialog(
						new JFrame(), true);
				dialog.addWindowListener(new java.awt.event.WindowAdapter() {
					@Override
					public void windowClosing(java.awt.event.WindowEvent e) {
						System.exit(0);
					}
				});
				dialog.setVisible(true);
			}
		});
	}

	public EmployeeMainPanel getEmp() {
		return emp;
	}

	public void setEmp(EmployeeMainPanel emp) {
		this.emp = emp;
	}

	public JButton getBtn_emdlg_cancel() {
		return btn_emdlg_cancel;
	}

	public void setBtn_emdlg_cancel(JButton btn_emdlg_cancel) {
		this.btn_emdlg_cancel = btn_emdlg_cancel;
	}

	public JButton getBtn_emdlg_savechange() {
		return btn_emdlg_savechange;
	}

	public void setBtn_emdlg_savechange(JButton btn_emdlg_savechange) {
		this.btn_emdlg_savechange = btn_emdlg_savechange;
	}

	public JComboBox<String> getCbb_emdlg_sex() {
		return cbb_emdlg_sex;
	}

	public void setCbb_emdlg_sex(JComboBox<String> cbb_emdlg_sex) {
		this.cbb_emdlg_sex = cbb_emdlg_sex;
	}

	public com.toedter.calendar.JDateChooser getDc_emdlg_birthday() {
		return dc_emdlg_birthday;
	}

	public void setDc_emdlg_birthday(
			com.toedter.calendar.JDateChooser dc_emdlg_birthday) {
		this.dc_emdlg_birthday = dc_emdlg_birthday;
	}

	public JScrollPane getjScrollPane1() {
		return jScrollPane1;
	}

	public void setjScrollPane1(JScrollPane jScrollPane1) {
		this.jScrollPane1 = jScrollPane1;
	}

	public JLabel getLbl_emdlg_address() {
		return lbl_emdlg_address;
	}

	public void setLbl_emdlg_address(JLabel lbl_emdlg_address) {
		this.lbl_emdlg_address = lbl_emdlg_address;
	}

	public JLabel getLbl_emdlg_birthday() {
		return lbl_emdlg_birthday;
	}

	public void setLbl_emdlg_birthday(JLabel lbl_emdlg_birthday) {
		this.lbl_emdlg_birthday = lbl_emdlg_birthday;
	}

	public JLabel getLbl_emdlg_email() {
		return lbl_emdlg_email;
	}

	public void setLbl_emdlg_email(JLabel lbl_emdlg_email) {
		this.lbl_emdlg_email = lbl_emdlg_email;
	}

	public JLabel getLbl_emdlg_name() {
		return lbl_emdlg_name;
	}

	public void setLbl_emdlg_name(JLabel lbl_emdlg_name) {
		this.lbl_emdlg_name = lbl_emdlg_name;
	}

	public JLabel getLbl_emdlg_newpassword() {
		return lbl_emdlg_newpassword;
	}

	public void setLbl_emdlg_newpassword(JLabel lbl_emdlg_newpassword) {
		this.lbl_emdlg_newpassword = lbl_emdlg_newpassword;
	}

	public JLabel getLbl_emdlg_personalID() {
		return lbl_emdlg_personalID;
	}

	public void setLbl_emdlg_personalID(JLabel lbl_emdlg_personalID) {
		this.lbl_emdlg_personalID = lbl_emdlg_personalID;
	}

	public JLabel getLbl_emdlg_phone() {
		return lbl_emdlg_phone;
	}

	public void setLbl_emdlg_phone(JLabel lbl_emdlg_phone) {
		this.lbl_emdlg_phone = lbl_emdlg_phone;
	}

	public JLabel getLbl_emdlg_sex() {
		return lbl_emdlg_sex;
	}

	public void setLbl_emdlg_sex(JLabel lbl_emdlg_sex) {
		this.lbl_emdlg_sex = lbl_emdlg_sex;
	}

	public JPanel getPn_emdlg_changeinfor() {
		return pn_emdlg_changeinfor;
	}

	public void setPn_emdlg_changeinfor(JPanel pn_emdlg_changeinfor) {
		this.pn_emdlg_changeinfor = pn_emdlg_changeinfor;
	}

	public JTextField getTxt_emdlg_email() {
		return txt_emdlg_email;
	}

	public void setTxt_emdlg_email(JTextField txt_emdlg_email) {
		this.txt_emdlg_email = txt_emdlg_email;
	}

	public JTextField getTxt_emdlg_name() {
		return txt_emdlg_name;
	}

	public void setTxt_emdlg_name(JTextField txt_emdlg_name) {
		this.txt_emdlg_name = txt_emdlg_name;
	}

	public JPasswordField getTxt_emdlg_newpassword() {
		return txt_emdlg_newpassword;
	}

	public void setTxt_emdlg_newpassword(JPasswordField txt_emdlg_newpassword) {
		this.txt_emdlg_newpassword = txt_emdlg_newpassword;
	}

	public JTextField getTxt_emdlg_personalID() {
		return txt_emdlg_personalID;
	}

	public void setTxt_emdlg_personalID(JTextField txt_emdlg_personalID) {
		this.txt_emdlg_personalID = txt_emdlg_personalID;
	}

	public JTextField getTxt_emdlg_phone() {
		return txt_emdlg_phone;
	}

	public void setTxt_emdlg_phone(JTextField txt_emdlg_phone) {
		this.txt_emdlg_phone = txt_emdlg_phone;
	}

	public JTextArea getTxta_emdlg_address() {
		return txta_emdlg_address;
	}

	public void setTxta_emdlg_address(JTextArea txta_emdlg_address) {
		this.txta_emdlg_address = txta_emdlg_address;
	}

	public ChangePasswordController getController() {
		return controller;
	}

	public static void setController(ChangePasswordController c) {
		controller = c;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public static void setInstance(EmployeeChangePasswordDialog instance) {
		EmployeeChangePasswordDialog.instance = instance;
	}
	
	

}
